package com.aaa.phone.controller.appuserwalletcontroller;

import com.aaa.entity.AppUserWallet;
import com.aaa.phone.service.appuserwalletservice.AppUserWalletService;
import com.aaa.phone.systemconst.ISystemConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: 此controller主要实现用户钱包余额、充值和提现
 * @Author: 陈阳
 * @CreateDate: 2018/12/21$ 20:34$
 */
@CrossOrigin
@Controller
@RequestMapping("/appUserWallet")
public class AppUserWalletController {

    @Autowired
    private AppUserWalletService service;

    /**
     * 获取用户余额
     */
    @RequestMapping("/getDefference")
    @ResponseBody
    public double getDefference(String telephone) {
        return service.getDefference(telephone);
    }
    /**
     * 用户充值
     * */
    @RequestMapping("/toRecharge")
    @ResponseBody
    //此注解为保证事务的一致性 如果充值成功之后到账出现问题则回滚，让其充值也失败，避免用户余额扣除而不到账
    @Transactional
    public double toRecharge(String telephone,double money) {
        return service.updateRecharge(telephone, money);
    }
     /**
      * 用户提现
      * */
    @RequestMapping("/toEnchashment")
    @ResponseBody
    //此注解为保证事务的一致性 如果提现成功之后到账出现问题则回滚，让其提现也失败，避免用户余额扣除而不到账
    @Transactional
    public double toEnchashment(String telephone,double money){
        return service.updateEnchashment(telephone, money);
    }
    /**
     * 用户消费（充值/提现）记录
     * */
    @RequestMapping("/showRechargeEnchashment")
    @ResponseBody
    public List<AppUserWallet> showRechargeEnchashment(String telephone){
        return service.getRechargeEnchashment(telephone);
    }
}
